#ifndef __PUSH_STREAM_H
#define __PUSH_STREAM_H
#include <string>
#include <memory>
#include "stream/rtc_stream.h"
#include "stream/rtc_packet.h"

namespace xrtc
{

    class PushStream : public RtcStream
    {
    public:
        PushStream(EventLoop *el, PortAllocator *alloctor, uint64_t uid, const std::string &stream_name,
                   bool audio, bool video, uint32_t log_id);
        ~PushStream() override;
        std::string CreateOffer() override;
        RtcStreamType StreamType() { return RtcStreamType::kPush; }
        void set_pli(bool is_pli) { pc->set_pli(is_pli); }
        bool GetAudioSource(std::vector<StreamParams> &source);
        bool GetVideoSource(std::vector<StreamParams> &source);
        std::shared_ptr<RtcPacket> FindVideoPacket(uint16_t seq_num);

    private:
        bool GetSource(const std::string &mid, std::vector<StreamParams> &source);
        void OnRtpPacket(PeerConnection *, webrtc::MediaType media_type, const webrtc::RtpPacketReceived &packet);
        void CacheVideoPacket(std::shared_ptr<RtcPacket> packet);
        void ProcessVideoPacket(std::shared_ptr<RtcPacket> packet);
        void OnFrame(PeerConnection *, RtpFrameObject *frame);
        void ClearVideoPacketCache(uint16_t start_seq, uint16_t stop_seq);

    private:
        std::vector<std::shared_ptr<RtcPacket>> video_data_buffer_;
        uint16_t video_seq_ = 0; // 当前连续的最大的包的序列号
        int64_t first_seq_time_ = -1;
    };

} // namespace xrtc

#endif